﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using CuaHangMayTinh.DataAccessLayer;
using CuaHangMayTinh.BusinessEntities;
using CuaHangMayTinh.Utilities;
using System.Data;

namespace CuaHangMayTinh.BusinessLogicLayer
{
    /// <summary>
    /// 
    /// </summary>
    public class NhapHangManager
    {
        /// <summary>
        /// 
        /// </summary>
        private static NhapHangDA adapter = null;

        static NhapHangManager()
        {
            if (adapter == null)
                adapter = new NhapHangDA();
        }

        /// <summary>
        /// 
        /// </summary>
        /// <param name="entity"></param>
        /// <returns></returns>
        public static int Insert(NhapHangEntity entity)
        {
            try
            {
                return adapter.Insert(entity);
            }
            catch (Exception ex)
            {
                Logger.Write(ex);
                return 0;
            }
        }

        /// <summary>
        /// Nhập tất cả thông tin của 1 hoa đơn nhập hàng
        /// </summary>
        /// <param name="entity"></param>
        /// <returns></returns>
        /// 
        public static int InsertTS(NhapHangEntity entity)
        {
            try
            {
                return adapter.InsertTS(entity);
            }
            catch (Exception ex)
            {
                Logger.Write(ex);
                return 0;
            }
        }

        /// <summary>
        /// 
        /// </summary>
        /// <param name="entity"></param>
        /// <param name="errormessage"></param>
        /// <returns></returns>
        public static int InsertTS(NhapHangEntity entity, ref string errormessage)
        {
            try
            {
                return adapter.InsertTS(entity);
            }
            catch (Exception ex)
            {
                errormessage = ex.Message;
                Logger.Write(ex);
                return 0;
            }
        }

        /// <summary>
        /// 
        /// </summary>
        /// <param name="entity"></param>
        /// <returns></returns>
        public static bool UpDate(NhapHangEntity entity)
        {
            try
            {
                return adapter.UpDate(entity);
            }
            catch (Exception ex)
            {
                Logger.Write(ex);
                return false;
            }
        }


        /// <summary>
        /// 
        /// </summary>
        /// <param name="View"></param>
        /// <returns></returns>
        public static DataTable Find_All(bool View)
        {
            try
            {
                return adapter.Find_All(View);
            }
            catch (Exception ex)
            {
                Logger.Write(ex);
                return null;
            }
        }

        /// <summary>
        /// 
        /// </summary>
        /// <param name="View"></param>
        /// <param name="errormessage"></param>
        /// <returns></returns>
        public static DataTable Find_All(bool View, ref string errormessage)
        {
            try
            {
                return adapter.Find_All(View);
            }
            catch (Exception ex)
            {
                errormessage = ex.Message;
                Logger.Write(ex);
                return null;
            }
        }

        /// <summary>
        /// 
        /// </summary>
        /// <param name="id"></param>
        /// <returns></returns>
        public static DataTable Find_ID(int id)
        {
            try
            {
                return adapter.Find_ID(id);
            }
            catch (Exception ex)
            {
                Logger.Write(ex);
                return null;
            }
        }

        public static NhapHangEntity GetAllInfo_ID(int MaNhapHang)
        {
            try
            {
                return adapter.GetAllInfo_ID(MaNhapHang);
            }
            catch (Exception ex)
            {
                Logger.Write(ex);
                return null;
            }
        }

        /// <summary>
        /// 
        /// </summary>
        /// <param name="dt"></param>
        /// <returns></returns>
        public static List<NhapHangEntity> ConvertToList(DataTable dt)
        {
            try
            {
                return adapter.ConvertToList(dt);
            }
            catch (Exception ex)
            {
                Logger.Write(ex);
                return null;
            }
        }

    }
}
